import http from '../../utils/http'
import type {ApiResponse, PageResult} from '../../utils/ApiResponse'
import {Merchants, PageMerchant} from "./types/merchant.dto.ts";

// 获取所有商家
export const getAllMerchants = (data: PageMerchant): Promise<PageResult<Object>> => {
    return http.get(`/merchants/info`, {
        params: {
            page: data.page,
            limit: data.limit,
            merchantName: data.merchantName,
            categoryId: data.categoryId,
            merchantStatus: data.merchantStatus,
        }
    })
}

// 获取商家详情
export const getMerchantDetail = (id: number): Promise<ApiResponse<Merchants>> => {
    return http.get(`/merchants/info/${id}`)
}

// 根据用户id获取商家信息
export const getMerchantByUserId = (userId: number): Promise<ApiResponse<Merchants>> => {
    return http.get(`/merchants/my/${userId}`)
}

// 修改商家状态
export const updateMerchantStatus = (id: number, status: string): Promise<ApiResponse<Object>> => {
    return http.put(`/merchants/${id}/status`, { status })
}

// 新增商家
export const addMerchant = (data: Merchants): Promise<ApiResponse<Object>> => {
    return http.post(`/merchants/save`, data)
}

// 修改商家
export const updateMerchant = (data: Merchants): Promise<ApiResponse<Object>> => {
    return http.put(`/merchants/save`, data)
}

// 审核商家
export const reviewMerchant = (id: number): Promise<ApiResponse<Object>> => {
    return http.put(`/merchants/${id}/review`)
}

// 删除商家
export const delMerchant = (id: number): Promise<ApiResponse<Object>> => {
    return http.put(`/merchants/delete/${id}`)
}

// 获取商品类别
export const getCategoryList = (): Promise<PageResult<Object>> => {
    return http.get(`/categories/info`)
}